package com.renli.service.impl;

import com.renli.bean.ResultJson;
import com.renli.mapper.PersonnelManagementMapper;
import com.renli.mapper.RecruitMapper;
import com.renli.mapper.RoleMapper;
import com.renli.pojo.*;
import com.renli.pojo.Event;
import com.renli.service.PersonnelManagementService;
import com.renli.service.RecruitService;
import com.renli.service.TodolistService;
import com.renli.vo.InterviewVo;
import com.renli.vo.SelectArchives;
import com.renli.vo.SelectChangeStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TodolistServiceImpl implements TodolistService {
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    RecruitMapper recruitMapper;
    @Autowired
    PersonnelManagementMapper personnelManagementMapper;
    @Autowired
    RecruitService recruitService;
    @Autowired
    PersonnelManagementService personnelManagementService;
    @Override
    public ResultJson selectTodolist(User user) {
        ResultJson resultJson=new ResultJson();
       List<Integer> roles= roleMapper.selectByUserId(user);
      List<Event> events= roleMapper.selectTodolist(roles);

        return resultJson.setSuccess("成功",events);
    }

    @Override
    public ResultJson handleTodolist(Event event) {
        ResultJson resultJson=new ResultJson();
        Integer eventTypeId = event.getEventTypeId();
        if (eventTypeId>=1&&eventTypeId<=4){
       Resume resume=recruitMapper.selectResumeByEvent(event);
            InterviewVo interviewVo=new InterviewVo();
            interviewVo.setUserId(event.getUserId());
            interviewVo.setEventId(event.getId());
            interviewVo.setOpinion(event.getOpinion());
            interviewVo.setRealName(resume.getRealName());
            interviewVo.setResumeId(resume.getId());
         return    recruitService.insertInterview(interviewVo);
        }
        if(eventTypeId==8){
        return     personnelManagementService.insertArchivesReview(event);
        }
        if (eventTypeId==7){
            ChangeStatistics changeStatistics = personnelManagementMapper.selectChangeStatisticsByEvent(event);
          return   personnelManagementService.updateChangeStatisticsReview(changeStatistics,event);
        }
       return null;
    }

    @Override
    public ResultJson selectHandleTodolist(Event event) {
        ResultJson resultJson=new ResultJson();
        Integer eventTypeId = event.getEventTypeId();
        if (eventTypeId>=1&&eventTypeId<=4){
            Resume resume=recruitMapper.selectResumeByEvent(event);
            Map map=new HashMap();
           map.put("resumeId",resume.getId());
            return    recruitService.selectOneResume(map);
        }
        if(eventTypeId==8){
            Archives archives = personnelManagementMapper.selectArchivesByEvent(event);
            SelectArchives selectArchives = new SelectArchives();
            selectArchives.setId(archives.getId());

            return     personnelManagementService.selectArchives(selectArchives);
        }
        if (eventTypeId==7){
            ChangeStatistics changeStatistics = personnelManagementMapper.selectChangeStatisticsByEvent(event);
            SelectChangeStatisticsVo selectChangeStatisticsVo=new SelectChangeStatisticsVo();
            selectChangeStatisticsVo.setChangeStatisticsId(changeStatistics.getId());
            return   personnelManagementService.selectChangeStatistics(selectChangeStatisticsVo);
        }
        return null;
    }


}
